React = require('react')
Card = require('antd-mobile/lib/card')
# ListView = require('antd-mobile/lib/list-view')
Flex = require('antd-mobile/lib/flex')
Icon = require('antd-mobile/lib/icon')
Toast = require('antd-mobile/lib/toast')
TimerMixin = require('react-timer-mixin')
RefreshControl = require('antd-mobile/lib/refresh-control')
{View,Image,TouchableNativeFeedback,Linking,Text,ScrollView,TouchableHighlight,StyleSheet,Navigator,ListView,TouchableOpacity} = require('react-native')
Dimensions = require('Dimensions')
{ width, height } = Dimensions.get('window')
{View} = require('react-native')
{fetchGetList,fetchRefreshList} = require('../actions/page_outplan.js')
{connect} = require('react-redux')
_ = require('underscore')
moment = require('moment')
DescPage = require('./page_outDesc.js')



backImg = require('../img/back.png')
searchIcon = require('../img/search_white.png')
basePage = require('../mixins/planBasePage.js')
Page_Outplan = React.createClass
  mixins:[basePage,TimerMixin]
  rowClick:(id)->
    debugger
    {navigator} = @props
    setTimeout ->
      navigator.push
        component:DescPage
        name:'outAttempDesc'
        title:'出口调度'
        params:
          id:id
    ,200
  _processDateTime:(date)->
    m = moment(date)
    if(m.isValid())
      m.format('DD/HHmm')
    else
      ""
  phoneClickHandle:(number)->
    url = "tel:#{number}"
    this.setTimeout ->
      Linking.canOpenURL(url).then (supported)->
        if supported
          Linking.openURL(url)
        else
          Toast.show("不能识别当前号码")
    ,200
  _renderRow:(rowData,sectionID,rowID,highlightRow)->
    <TouchableHighlight
      onPress={=>
        if @props.userInfo.pilotCode not in ['guest','',null]
          this.rowClick(rowData.CHDYNPLANID)
        # highlightRow(sectionID,rowID)
      } key={rowID}>
      <View  style={{overflow:'hidden',flexDirection:'row',justifyContent:'center',alignItems:'flex-start',backgroundColor:'#F6F6F6'}}>
        <View style={{marginLeft:5,marginTop:10}}>
          <Text style={{color:'#0066FF'}}>{"#{rowData.sortNum}."}</Text>
        </View>
        <View style={[styles.row,{flex:1}]}>
          <Text style={[styles.text,{fontWeight:'bold'}]}>
            {"#{rowData.VCVESCNAME}            #{rowData.VCVESENAME}"}
          </Text>
          <View style={{flexDirection:'row'}}>
            <Text style={{marginRight:10}}>
              {"#{rowData.NMVESLENGTH}/#{rowData.NMVESWIDTH}/#{rowData.NMBACKGUAGE}/#{rowData.CHENDPLACENAME}"}
            </Text>
            <Text style={styles.text}>
              {"#{this._processDateTime(rowData.SDLEAVETIMEPILOTAGE)}/#{rowData.CHARRIVEPLACESIGN}"}
            </Text>
          </View>
          {
            if @props.userInfo.pilotCode not in ['guest','',null]
                <View style={{flexDirection:'row'}}>
                  <View style={{flex:1,flexDirection:'row'}}>
                    <Text>{"#{rowData.FULLPILOTNAME}"}</Text>
                    <TouchableHighlight onPress={@phoneClickHandle.bind(@,rowData.FULLPILOTPHONE)}>
                      <View style={{paddingLeft:10,paddingRight:10}}>
                        <Text style={styles.phone}>{"#{rowData.FULLPILOTPHONE}"}</Text>
                      </View>
                    </TouchableHighlight>
                  </View>
                  <View style={{flex:1,flexDirection:'row'}}>
                    {
                        if rowData.MOVEPILOTNAME
                          rtl =[
                            <Text key="1">{"#{rowData.MOVEPILOTNAME}"}</Text>
                            <TouchableHighlight key="2" onPress={@phoneClickHandle.bind(@,rowData.MOVEPILOTPHONE)}>
                              <View style={{paddingLeft:10,paddingRight:10}}>
                                <Text style={styles.phone}>{"#{rowData.MOVEPILOTPHONE}"}</Text>
                              </View>
                            </TouchableHighlight>]
                        else
                          rtl = [
                            <Text key="1">{"#{rowData.FULLPILOTNAME2}"}</Text>
                            <TouchableHighlight key="2" onPress={@phoneClickHandle.bind(@,rowData.FULLPILOTPHONE2)}>
                              <View style={{paddingLeft:10,paddingRight:10}}>
                                <Text style={styles.phone}>{"#{rowData.FULLPILOTPHONE2}"}</Text>
                              </View>
                            </TouchableHighlight>]
                    }
                  </View>
                </View>
          }

        </View>
      </View>
    </TouchableHighlight>
    # <TouchableHighlight onPress={@rowClick.bind(@,rowData.CHDYNPLANID)} key={rowData.CHDYNPLANID}>
    #   <View  style={{flexDirection:'row',justifyContent:'center',alignItems:'flex-start',backgroundColor:'#F6F6F6'}}>
    #     <View style={{width:25,marginLeft:5,marginTop:10}}>
    #       <Text style={{color:'#0066FF'}}>{rowData.sortNum}</Text>
    #     </View>
    #     <View style={[styles.row,{flex:1}]}>
    #       <Text style={[styles.text,{fontWeight:'bold'}]}>
    #         {"#{rowData.VCVESCNAME}            #{rowData.VCVESENAME}"}
    #       </Text>
    #       <View style={{flexDirection:'row'}}>
    #         <Text style={styles.text}>
    #           {"船长/船宽/吃水"}
    #         </Text>
    #         <Text style={styles.text}>
    #           {"#{rowData.NMVESLENGTH}/#{rowData.NMVESWIDTH}/#{rowData.NMFRONTGUAGE}"}
    #         </Text>
    #       </View>
    #       <View style={{flexDirection:'row'}}>
    #         <Text style={styles.text}>
    #           {"离泊泊位:#{rowData.CHARRIVEPLACESIGN}"}
    #         </Text>
    #         <Text style={styles.text}>
    #           {"离泊时间:#{moment(rowData.SDLEAVETIMEPILOTAGE).format('MMDD/HHmm')}"}
    #         </Text>
    #       </View>
    #     </View>
    #   </View>
    # </TouchableHighlight>

styles = StyleSheet.create
  row:
    flexDirection:'column'
    justifyContent:'center'
    padding:10
  text:
    flex:1
  phone:
    flex:1
    textDecorationLine:'underline'
    color:'#0066FF'

mapStateToProps = (state)->
  debugger
  list:state.page_outplan.list
  isLoading:state.page_outplan.isLoading
  pageIndex:state.page_outplan.pageIndex
  completed:state.page_outplan.completed
  refreshing:state.page_outplan.refreshing
  lastFetchTime:state.page_outplan.lastFetchTime
  connected:state.appState.connected
  userInfo:state.userInfo

mapDispatchToProps = (dispatch,wonProps)->
  fetchGet:(pageNum,state)->
    dispatch fetchGetList(pageNum,state)
  fetchRefresh:(state)->
    dispatch fetchRefreshList(state)

module.exports = connect(mapStateToProps,mapDispatchToProps)(Page_Outplan)
